package com.zline.foodraise.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zline.foodraise.R;
import com.zline.foodraise.entity.ShareChannel;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;
import org.androidannotations.annotations.SystemService;

import java.util.List;

/**
 * Created by heshantao on 15/8/11.
 * 分享平台Adapter
 */
@EBean
public class ShareChannelsAdapter extends BaseAdapter {
    private static final String LOG_TAG = ShareChannelsAdapter.class.getSimpleName();
    List<ShareChannel> list;
    @SystemService
    LayoutInflater layoutInflater;
    @RootContext
    Context cxt;

    public void setData(List<ShareChannel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public ShareChannel getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ShareChannel shareChannel = getItem(position);
        ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.share_channel_item, parent, false);
            holder = new ViewHolder();
            holder.icon_iv = (ImageView) convertView.findViewById(R.id.share_icon_iv);
            holder.name_tv = (TextView) convertView.findViewById(R.id.share_name_tv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name_tv.setText(shareChannel.getName());
        Bitmap bitmap = BitmapFactory.decodeResource(cxt.getResources(), shareChannel.getIcoRes());
        holder.icon_iv.setImageBitmap(bitmap);
        return convertView;
    }

    static class ViewHolder {
        ImageView icon_iv;
        TextView name_tv;

    }
}
